﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Genuilder.Extensibility
{
	public class GenItemCollection : IEnumerable<GenItem>
	{
		List<GenItem> _Items;

		public GenItemCollection(IEnumerable<GenItem> items)
		{
			if(items == null)
				throw new ArgumentNullException("items");
			_Items = items.ToList();
		}
		#region IEnumerable<GenItem> Members

		public IEnumerator<GenItem> GetEnumerator()
		{
			return _Items.GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		#endregion

		public IEnumerable<GenItem> GetByNames(params string[] files)
		{
			if(files == null)
				yield break;
			foreach(var item in _Items)
			{
				if(files.Contains(item.Name))
					yield return item;
				else
				{
					if(files.Contains(item.Name.Split('\\', '/').Last()))
						yield return item;
				}
			}
		}
	}
}
